import java.util.Arrays;

public class ArraySortandLookup {
    //数组作为返回值的类型
    public static int[] fun(){
        int[] arr={12,45,21,456};
        return arr;
    }
    //无返回值进行对数组的修改
    public static void fun2(int[] arr){
        for (int i=0;i<arr.length;i++){
            arr[i]*=2;//arr[i]=arr[i]*2,改变了堆上的元素
        }
    }
    //将数组打印成字符串
    public static String myTOstring(int[] arr){
        if (arr==null)
            return null;
        String ret="[";
        for (int i = 0; i < arr.length; i++) {
            ret+=arr[i];
            if (i!=arr.length){
                ret+=",";
            }


        }
        ret+="]";
        return ret;
    }
    //数组拷贝
    public static void CParr(int[] arr){
        int[] arr2=new int[arr.length];
        for (int i = 0; i < arr.length; i++) {
            arr2[i]=arr[i];
        }
        System.out.println(Arrays.toString(arr));
        System.out.println(Arrays.toString(arr2));
    }
    //JAVA复制函数
    public static int[] CP1(int[] arr){
        int[] ret=Arrays.copyOf(arr,arr.length);//原始数组，原始数组长度，返回一个数组
        return ret;
    }
    public static void main(String[] args) {
        //int[] arr1=fun();
        //System.out.println(Arrays.toString(arr1));
        int[] arr2=new int[]{12,13,14,15};
        /*fun2(arr2);
        System.out.println(Arrays.toString(arr2));*/
        CParr(arr2);

    }
}

